﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LF3.Moduls;
using LF3.Repositories;
using System.Data;

namespace LF3.Controllers
{
    public class Operate_LogController
    {
        Operate_LogRepository rep = new Operate_LogRepository();
         
        public IList<Operate_Log> GetOperateLogCondition(string heatid,string start ,string end)
        {
            string condition="";
            if (!string.IsNullOrEmpty(heatid))
                condition += string.Format(@" and upper(op_key1) like '%{0}%' ",heatid.ToUpper());
            if (!string.IsNullOrEmpty(start))
                condition += string.Format(@" and op_date >= to_date('{0}','yyyy-mm-dd') ", start);
            if (!string.IsNullOrEmpty(end))
                condition += string.Format(@" and op_date < to_date('{0}','yyyy-mm-dd') ", end);
            return rep.GetOperateLogCondition(condition);
        }

        public IList<Lf_Heat_Event> GetHeatEventCondition(string heatid, string start, string end)
        {
            string condition = "";
            if (!string.IsNullOrEmpty(heatid))
                condition += string.Format(@" and upper(heatid) like '%{0}%' ", heatid.ToUpper());
            if (!string.IsNullOrEmpty(start))
                condition += string.Format(@" and insert_time >= to_date('{0}','yyyy-mm-dd') ", start);
            if (!string.IsNullOrEmpty(end))
                condition += string.Format(@" and insert_time < to_date('{0}','yyyy-mm-dd') ", end);
            return rep.GetHeatEventCondition(condition);
        }

        public IList<Plc_Mat> GetPlcMatCondition(string start, string end)
        {
            string condition = ""; 
            if (!string.IsNullOrEmpty(start))
                condition += string.Format(@" and t1.inserttime >= to_date('{0}','yyyy-mm-dd') ", start);
            if (!string.IsNullOrEmpty(end))
                condition += string.Format(@" and t1.inserttime < to_date('{0}','yyyy-mm-dd') ", end);
            return rep.GetPlcMatCondition(condition);
        }

        public IList<Lf_Event_Code> GetAllCode()
        {
            return rep.GetAllCode();
        }
        
    }
}
